from django.shortcuts import render
from web.views.chatbot.chatbot_graph import ChatBotGraph
from web.views.chatbot.conversation_save import ConversationSave

handler = ChatBotGraph()
con_save = ConversationSave()


def get_content(request):
    send_Value = request.GET.get("sendValue") or ""
    if send_Value and send_Value != "":
        # 对send_Value进行处理，获取chatbot的回答
        con_save.addCon(send_Value)
        response = handler.chat_main(send_Value)
        con_save.addCon(response)
    else:
        response = "您好，我是寻医问药网站自动问答AI，希望可以帮到您。"
        if len(con_save.getlist()) == 0:
            con_save.addCon(response)

    result = con_save.getlist()
    context = {
        'response': result
    }
    return render(request, 'chatbot.html', context)
